package com.ludomancy.archeologyrpg;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.util.Iterator;

import com.ludomancy.gamelib.ResourceManager;
import com.ludomancy.gamelib.Utils;
import com.ludomancy.gamelib.Widget;

public class PhotographyWidget extends Widget
{
	public Image grayBackground;
	
	public PhotographyWidget(Widget parent, Rectangle area)
	{
		super(parent, area);
		grayBackground = ResourceManager.getImage("oldBackground.png");
	}

	public void paint(Graphics g)
	{
		GameTheme.theme.fillStatusbarBackground(g, getClientRect());
		
		// paint picture grid
		g.setColor(GameTheme.theme.getStatusbarBorderColor());
		for (int i = 0; i < Game.PHOTO_MAX; i++)
		{
			g.drawLine(i*Game.PHOTO_SIZE, 0, i*Game.PHOTO_SIZE, getHeight());
		}
		
		int offset = 0;
		for (Iterator iter = Game.game.photographies.iterator(); iter.hasNext();)
		{
			Entity photo = (Entity) iter.next();
			// paint the background
			g.setColor(Color.WHITE);
			g.fillRect(offset, 0, Game.PHOTO_SIZE, Game.PHOTO_SIZE);
			int centerX = offset + Game.PHOTO_SIZE/2;
			int centerY = Game.PHOTO_SIZE/2;
			int actualSize = Game.PHOTO_SIZE-8;
			Utils.drawImage(g, grayBackground, 
							centerX, 
							centerY,
							photo.px-actualSize/2,
							photo.py-actualSize/2,
							actualSize,
							actualSize,
							Utils.ANCHOR_HCENTER|Utils.ANCHOR_VCENTER);
			// paint the building
			photo.paint(g, offset + Game.PHOTO_SIZE/2, Game.PHOTO_SIZE/2);
			g.setColor(Color.BLACK);
			g.drawRect(offset, 0, Game.PHOTO_SIZE, Game.PHOTO_SIZE);
			offset += Game.PHOTO_SIZE;
		}
	}
}
